// https://nuxt.com/docs/api/configuration/nuxt-config
import createVitePlugins from './vite/plugins';

export default defineNuxtConfig({
  compatibilityDate: '2024-11-01',
  devtools: { enabled: true },
  runtimeConfig: {
    // 私有变量（仅服务端可用）
    apiSecret: process.env.NUXT_API_SECRET,

    // 公开变量（客户端和服务端均可访问）
    public: {
      appBaseUrl: process.env.NUXT_PUBLIC_APP_BASE_URL,
      appBaseApi: process.env.NUXT_PUBLIC_APP_BASE_API,
      appPort: process.env.NUXT_PUBLIC_APP_PORT,
      appTitle: process.env.NUXT_PUBLIC_APP_TITLE, // 新增：API 标题
    },
  },

  // 配置 Vite 以支持 SCSS
  vite: {
    plugins: createVitePlugins(process.env),
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@use "~/assets/style/index.scss";`
        }
      }
    }
  },
  devServer: {
    port: process.env.NUXT_PUBLIC_APP_PORT, // 设置新端口
    host: 'http://localhost' // 允许外部访问
  },
  nitro: {
    devProxy: {
      [process.env.NUXT_PUBLIC_APP_BASE_API]: {
        target: 'http://localhost:8080/api', // 实际后端地址
        changeOrigin: true,
        // 新增排除路径
        bypass: (req) => {
          if (req.path?.startsWith('/_nuxt/') || req.path?.startsWith('/_vercel/')) return req.path;
        }
      },
    }
  },

  modules: [
    '@pinia/nuxt',
    '@element-plus/nuxt',
  ],
  elementPlus: {
    importStyle: 'scss',
    injections: ['$message'],
    // 新增样式配置
    styles: [
      'element-plus/theme-chalk/src/base.scss'
    ]
  },

  // 新增插件配置
  plugins: [
    '~/plugins/router-interceptor.ts'
  ]
})